package org.acghub.mtdb.common;

import org.acghub.mtdb.util.ElementHelper;
import org.w3c.dom.Element;

import java.util.List;
import java.util.Set;

/**
 * @author zhouhe
 */
public class Bean extends Type implements Meta {
    private String comment;

    public Bean(Mtdb parent, Element self) throws Exception {
        super(parent, self);
    }


    @Override
    public void initialize(Element self) throws Exception {
        ElementHelper eh = new ElementHelper(self);
        Verify.verifyName(Verify.VerifyType.BEAN, getName());
        this.comment = eh.getString("comment", "");
        eh.warnUnused("name");
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }

    @Override
    public void depends(Set<Type> types) {
        if (types.add(this)) {
            this.getVars().forEach(var -> var.depends(types));
        }
    }

    public String getComment() {
        return comment;
    }

    public List<Var> getVars() {
        return getChildren(Var.class);
    }

    /**
     * 获取java接口类型
     *
     * @return
     */
    @Override
    public String javaInterfaceType() {
        return getName();
    }

    /**
     * 获取java实现类型
     *
     * @return
     */
    @Override
    public String javaImplType() {
        return getName();
    }
}
